﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;
using System.Security.Cryptography;

namespace ServeNHL.Helpers
{
    public class UserHelper
    {
        public static string getPasswordSaltHash(string password)
        {
            String salt = "";
            StringBuilder tmpStr = new StringBuilder();
            SHA512 hash = SHA512.Create();
            string returnHash = "";
            salt = WebConfigurationManager.AppSettings["DB.Password.Salt"];

            tmpStr.Append(password);
            tmpStr.Append(salt);

            byte[] hashResult = hash.ComputeHash(Encoding.UTF8.GetBytes(tmpStr.ToString()));
            returnHash = Encoding.UTF8.GetString(hashResult);
            return returnHash;
        }

        /* public string getUsername (int userId)
         {
             int id;
             //query to return name
            // using (var db = new )
             return id;
         }

         //METHOD to get user role return string
         */
     

        /// <summary>
        /// Given a password length and number of special characters, generates a random temporary password.
        /// </summary>
        /// <param name="passwordLength">Length of password. If no value is given, it is 8 characters long.</param>
        /// <param name="numberOfSpecialCharacters">Number of special characters in the generated password. If no value is given, it will use 1 special characters</param>
        /// <returns>Random temporary password.</returns>
        public static string createTempPassword(int passwordLength = 8, int numberOfSpecialCharacters = 0)
        {
            string password = "";
            password = System.Web.Security.Membership.GeneratePassword(passwordLength, numberOfSpecialCharacters);
            return password;
        }
    }
}

